'use strict';
var router = require('express').Router();

router.get('/:id', function(req, res, next) {
    var query = new AV.Query('_User');
    query.get(req.params.id).then(user=>{
        res.send(user)
    },error=>{
        res.send(error)
    })
})

// 新增用户
router.post('/signup', function(req, res, next) {
    var user = new AV.User();
    user.setUsername(req.body.username);
    user.setPassword(req.body.password);
    user.setEmail(req.body.email);
    user.signUp().then( loginedUser => {
        res.send(loginedUser)
    }, error =>{
        res.send(error)
    })

});
// 登录
router.post('/login', function(req, res, next) {
    AV.User.logIn(req.body.username,req.body. password).then(function (loginedUser) {
        res.send(loginedUser)
    }, function (error) {
        res.send(error)
    });
});



module.exports = router;
